/**
 * @ClassName DateUtils
 * @Description TODO
 * @Author 沉默小吴
 * @Date 2024/12/25 9:21
 */
package com.tledu.operate.count.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

public class DateUtils {

    /**
     * 初始化日期时间，使startDate为年月日0时0分0秒，endDate为年月日23时59分59秒
     *
     * @param startDate 只有年月日的开始日期
     * @param endDate   只有年月日的结束日期
     * @return 包含初始化后开始时间和结束时间的数组
     */
    private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    private static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public static String[] initializeDateTimes(String startDate, String endDate) throws DateTimeParseException {
        LocalDate startLocalDate = LocalDate.parse(startDate, DATE_FORMATTER);
        LocalDate endLocalDate = LocalDate.parse(endDate, DATE_FORMATTER);

        LocalDateTime startDateTime = startLocalDate.atStartOfDay(); // 设置为0时0分0秒
        LocalDateTime endDateTime = endLocalDate.atTime(LocalTime.MAX); // 设置为23时59分59秒

        return new String[]{
                startDateTime.format(DATETIME_FORMATTER),
                endDateTime.format(DATETIME_FORMATTER)
        };
    }
}